import React from "react";
import { NavBar, Space, Toast } from "antd-mobile";
import { useNavigate } from "react-router-dom";
// import { Form, Input, Button } from "antd-mobile";
import { Form, Input, Button } from "antd-mobile";
import styles from "./css/index.module.css";
import { zhuceApi } from "../../api/login";
function Index() {
  const tiao = useNavigate();
  const onFinish = async (values) => {
    console.log(values);
    const { data: res } = await zhuceApi(values);
    console.log(res);
    if (res == "注册成功！") {
      tiao("/login");
    }
  };
  return (
    <div>
      <NavBar onBack={() => tiao(-1)}></NavBar>
      <div className={styles.hezi}>注册账户</div>
      <Form
        onFinish={onFinish}
        layout="horizontal"
        footer={
          <Button block type="submit" color="primary" size="large">
            提交
          </Button>
        }
      >
        <Form.Item
          name="username"
          rules={[{ required: true, message: "用户名不能为空" }]}
        >
          <Input placeholder="用户名" />
        </Form.Item>
        <Form.Item
          name="email"
          rules={[{ required: true, message: "电子邮件不能为空" }]}
        >
          <Input placeholder="电子邮件" />
        </Form.Item>
        <Form.Item
          name="tel"
          rules={[{ required: true, message: "电话不能为空" }]}
        >
          <Input placeholder="电话" />
        </Form.Item>
        <Form.Item
          name="birth"
          rules={[{ required: true, message: "出生日期不能为空" }]}
        >
          <Input placeholder="出生日期" />
        </Form.Item>
        <Form.Item
          name="password"
          rules={[{ required: true, message: "密码不能为空" }]}
        >
          <Input placeholder="密码" />
        </Form.Item>
      </Form>
    </div>
  );
}

export default Index;
